package com.goods.controller.business;

import com.goods.business.service.BizConsumerService;
import com.goods.common.model.business.BizConsumer;
import com.goods.common.model.business.BizConsumer;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/consumer")
public class BizConsumerController {

    @Autowired
    private BizConsumerService bizConsumerService;

    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<BizConsumer> bizConsumerList = bizConsumerService.findAllConsumer();
        return ResponseBean.success(bizConsumerList);
    }
    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam Map<String,Object> queryMap){
        PageVO<ConsumerVO> consumerVOPageVO = bizConsumerService.findConsumerList(queryMap);
        return ResponseBean.success(consumerVOPageVO);
    }
    
    @PostMapping("/add")
    public ResponseBean addConsumer(@RequestBody ConsumerVO consumerVO){
        bizConsumerService.addConsumer(consumerVO);
        return ResponseBean.success();
    }

    @GetMapping("/edit/{id}")
    public ResponseBean editConsumer(@PathVariable Integer id) {
        ConsumerVO supplierVO = bizConsumerService.getConsumerVo(id);
        return ResponseBean.success(supplierVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateConsumer(@PathVariable Integer id, @RequestBody BizConsumer bizConsumer) {
        bizConsumerService.updateBizConsumer(id,bizConsumer);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteConsumer(@PathVariable Integer id){
        bizConsumerService.deleteConsumerById(id);
        return ResponseBean.success();

    }
    
}
